# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocp-indent
pkgver=1.8.1
pkgrel=0
pkgdesc="OCaml source code indenter"
url="http://www.typerex.org/ocp-indent.html"
arch="all !riscv64"  # limited by ocaml aport
license="LGPL-2.1-only-WITH-linking-exception"
_depends_ocaml="ocaml-runtime ocaml-findlib"
depends_dev="ocaml-cmdliner-dev ocaml-findlib-dev"
makedepends="$depends_dev dune ocaml"
subpackages="
	$pkgname-doc
	$pkgname-emacs::noarch
	$pkgname-vim::noarch
	ocaml-$pkgname-dev:_libdev
	ocaml-$pkgname:_lib
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/OCamlPro/ocp-indent/archive/$pkgver.tar.gz"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install --destdir="$pkgdir"
}

emacs() {
	pkgdesc="$pkgdesc for Emacs"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"

	amove usr/share/emacs
}

vim() {
	pkgdesc="$pkgdesc for vim"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	amove usr/share/ocp-indent/vim
}

_libdev() {
	pkgdesc="$pkgdesc (development files)"
	depends="$depends_dev ocaml-$pkgname=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; for path in $(find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done

}

_lib() {
	pkgdesc="$pkgdesc (library)"
	depends="$_depends_ocaml"

	amove usr/lib/ocaml
}

sha512sums="
565353de333dd44375366fff75e85a6256c3cd9ff52b3db79803141f975e77cda04dfe32f5e0f2d4c82c59be8f04e9c2bf4d066b113b2cdf267f4c3dcfa401da  ocp-indent-1.8.1.tar.gz
"
